package com.example.librarysystem.Controller;

import com.example.librarysystem.Dao.CreditDao;
import com.example.librarysystem.Service.*;
import com.example.librarysystem.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(value = "管理员控制器接口")
@Controller
public class AdminController {
    @Autowired
    private BooksService booksService;
    @Autowired
    private BorrowService borrowService;
    @Autowired
    private StarService starService;
    @Autowired
    private BookManagementService bookManagementService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private BorrowerService borrowerService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private CreditService creditService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private MailService mailService;
    @Autowired
    private BorrowerManagementService borrowerManagementService;

    private boolean confirm(HttpServletRequest request, String pwd){
        String p = (String) request.getSession().getAttribute("password");
        return p.equals(pwd);
    }

    @ApiOperation(value = "管理员欢迎页面")
    @GetMapping("/adminWelcome")
    public String adminWelcome(Model model, HttpServletRequest request){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        Integer borrowerNum = borrowerService.selectCount();
        Integer borrowNum = borrowService.selectCount();
        Integer commentNum = commentService.selectCount();
        Integer bookNum = booksService.selectCount();
        model.addAttribute("borrowerNum", borrowerNum);
        model.addAttribute("borrowNum",borrowNum);
        model.addAttribute("commentNum",commentNum);
        model.addAttribute("bookNum",bookNum);
        return "page/adminWelcome";
    }
    @ApiOperation(value = "管理员书籍管理")
    @GetMapping("/adminBook")
    public String adminBook(HttpServletRequest request){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminBook";
    }
    @ApiOperation(value = "管理员图书搜索")
    @GetMapping("/bookInfo")
    @ResponseBody
    public JsonObject bookInfo(HttpServletRequest request,int page, int limit) throws ParseException {
        String id = request.getParameter("id");
        String ISBN = request.getParameter("ISBN");
        String alias = request.getParameter("alias");
        String classification = request.getParameter("classification");
        String publishDate = request.getParameter("publishDate");
        String author = request.getParameter("author");
        String name = request.getParameter("name");
        String publishingHouse = request.getParameter("publishingHouse");
        String dateStart = request.getParameter("dateStart");
        String dateEnd = request.getParameter("dateEnd");
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        if(id == null){
            List<Books> books = booksService.selectAll(page, limit);
            jsonObject.setData(books);
            jsonObject.setCount((long)booksService.selectCount());
            return jsonObject;
        }
        AdminBook adminBook = new AdminBook();
        adminBook.setId("%"+id+"%");
        adminBook.setISBN("%"+ISBN+"%");
        adminBook.setAlias("%"+alias+"%");
        adminBook.setClassification("%"+classification+"%");
        adminBook.setPublishDate("%"+publishDate+"%");
        adminBook.setAuthor("%"+author+"%");
        adminBook.setName("%"+name+"%");
        adminBook.setPublishingHouse("%"+publishingHouse+"%");
        adminBook.setDateStart(dateStart);
        adminBook.setDateEnd(dateEnd);
        adminBook.setCurrentPage(page);
        adminBook.setPageSize(limit);
        List<Books> books = null;
        if(!dateStart.equals("")&&dateEnd.equals("")){
            books = adminService.selectBookAfter(adminBook,page,limit);
            jsonObject.setCount((long)adminService.selectBookAfterCount(adminBook));
        }else if(dateStart.equals("")&&!dateEnd.equals("")){
            books = adminService.selectBookBefore(adminBook,page,limit);
            jsonObject.setCount((long)adminService.selectBookBeforeCount(adminBook));
        }else if(!dateStart.equals("")){
            books = adminService.selectBookBetween(adminBook,page,limit);
            jsonObject.setCount((long)adminService.selectBookBetweenCount(adminBook));
        }else {
            books = adminService.selectBook(adminBook,page,limit);
            jsonObject.setCount((long)adminService.selectBookCount(adminBook));
        }
        jsonObject.setData(books);
        return jsonObject;
    }
    @ApiOperation(value = "管理员修改图书信息页面")
    @GetMapping("/updateBook")
    public String bookItem(HttpServletRequest request, Model model, int id){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        Books book = booksService.selectById(id);
        model.addAttribute("book", book);
        return "admin/updateBook";
    }
    @ApiOperation(value = "管理员修改图书信息")
    @PostMapping("/updateBook")
    @ResponseBody
    public R updateBook(HttpServletRequest request, @RequestParam("name") String name,
                        @RequestParam("alias") String alias, @RequestParam("author") String author,
                        @RequestParam("ISBN") String ISBN, @RequestParam("classification") String classification,
                        @RequestParam("intro") String intro, @RequestParam("publishingHouse") String publishingHouse,
                        @RequestParam("publishDate") String publishDate, @RequestParam("id") Integer id,
                        @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Books books = booksService.selectById(id);
        if(books != null){
            books.setName(name);
            books.setAlias(alias);
            books.setAuthor(author);
            books.setISBN(ISBN);
            books.setClassification(classification);
            books.setIntro(intro);
            books.setPublishingHouse(publishingHouse);
            books.setPublishDate(publishDate);
        }
        if(booksService.updateById(books) == 0){
            BookManagement bookManagement = new BookManagement();
            bookManagement.setBookId(id);
            bookManagement.setAdminId((int)request.getSession().getAttribute("id"));
            bookManagement.setDate(new Date());
            bookManagement.setOpType("update");
            bookManagementService.insertBookM(bookManagement);
            return R.ok();
        }
        return R.fail("请稍后再试");
    }
    @ApiOperation(value = "管理员添加图书")
    @PostMapping("/addBook")
    @ResponseBody
    public R addBook(HttpServletRequest request, @RequestParam("name") String name,
                     @RequestParam("alias") String alias, @RequestParam("author") String author,
                     @RequestParam("ISBN") String ISBN, @RequestParam("classification") String classification,
                     @RequestParam("intro") String intro, @RequestParam("publishingHouse") String publishingHouse,
                     @RequestParam("publishDate") String publishDate,@RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Books temp = booksService.selectByNameOnly(name);
        if(temp != null){
            if(!temp.getISBN().equals(ISBN)){
                return R.fail("已存在同名书籍，请用书名加特殊编号来区分");
            }
        }
        Books books = new Books();
        books.setName(name);
        books.setAlias(alias);
        books.setAuthor(author);
        books.setISBN(ISBN);
        books.setClassification(classification);
        books.setIntro(intro);
        books.setPublishingHouse(publishingHouse);
        books.setPublishDate(publishDate);
        books.setDate(new Date());
        books.setScore(-1);
        books.setBorrown(false);
        books.setTimes(0);
        int ret = -1;
        if(temp == null){
            Times times = new Times();
            times.setBookName(books.getName());
            times.setClickTimes(0);
            times.setSearchTimes(0);
            ret = booksService.insertBook(books,times);
        }else {
            ret = booksService.insertBook(books,null);
        }
        if(ret >= 0){
            BookManagement bookManagement = new BookManagement();
            bookManagement.setBookId(ret);
            bookManagement.setAdminId((int)request.getSession().getAttribute("id"));
            bookManagement.setDate(new Date());
            bookManagement.setOpType("add");
            bookManagementService.insertBookM(bookManagement);
            return R.ok();
        }
        return R.fail("请稍后再试");
    }
    @ApiOperation(value = "管理员删除图书")
    @PostMapping("/deleteBook")
    @ResponseBody
    public R deleteBook(HttpServletRequest request, @RequestParam("id") int id,
                        @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        if(booksService.deleteById(id) == 0){
            BookManagement bookManagement = new BookManagement();
            bookManagement.setBookId(id);
            bookManagement.setAdminId((int)request.getSession().getAttribute("id"));
            bookManagement.setDate(new Date());
            bookManagement.setOpType("delete");
            bookManagementService.insertBookM(bookManagement);
            return R.ok();
        }
        return R.fail("失败，请稍后再试");
    }
    @ApiOperation(value = "管理员借阅管理")
    @GetMapping("/adminBorrow")
    public String adminBorrow(HttpServletRequest request){
        String isLongin = (String) request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminBorrow";
    }
    @ApiOperation(value = "管理员借阅内容")
    @GetMapping("/adminBorrowInfo")
    @ResponseBody
    public JsonObject adminBorrowInfo(HttpServletRequest request,int page, int limit){
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<Borrow> borrows = borrowService.selectBorrowAll(page, limit);
        for(int i = 0; i < borrows.size(); ++i){
            if(borrows.get(i).getIsReturn()){
                borrows.get(i).setFlag("是");
            }else {
                borrows.get(i).setFlag("否");
            }
        }
        jsonObject.setData(borrows);
        jsonObject.setCount((long)borrowService.selectCount());
        return jsonObject;
    }
    @ApiOperation(value = "管理员发送催还邮件")
    @PostMapping("/push")
    @ResponseBody
    public R push(HttpServletRequest request, @RequestParam("id") int id,
                  @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        Integer borrowerId = (Integer)request.getSession().getAttribute("id");
        Borrower borrower = borrowerService.selectById(borrowerId);
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Borrow borrow = borrowService.selectById(id);
        if(borrow==null){
            return R.fail("错误");
        }
        mailService.sendReturnMail(borrower.getEmail(),borrow.getEnd(), borrow.getBookName(),borrow.getBorrowerName());
        return R.ok();
    }
    @ApiOperation(value = "管理员预约管理页面")
    @GetMapping("/adminOrder")
    public String adminOrder(HttpServletRequest request){
        String isLongin = (String) request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminOrder";
    }
    @ApiOperation(value = "管理员预约信息详情")
    @GetMapping("/adminOrderInfo")
    @ResponseBody
    public JsonObject adminOrderInfo(int page, int limit, HttpServletRequest request){
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<Order> orders = orderService.selectAll(page, limit);
        jsonObject.setData(orders);
        jsonObject.setCount((long)orderService.selectCount());
        return jsonObject;
    }
    @ApiOperation(value = "管理员发送预约邮件")
    @PostMapping("/pushOrder")
    @ResponseBody
    public R pushOrder(HttpServletRequest request, @RequestParam("id") int id,
                       @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        Integer borrowerId = (Integer)request.getSession().getAttribute("id");
        Borrower borrower = borrowerService.selectById(borrowerId);
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Order order = orderService.selectOrderById(id);
        if(order==null){
            return R.fail("错误");
        }
        //System.out.println("email1");
        mailService.sendOrderMail(borrower.getEmail(),order.getStartDate(),order.getEndDate(),order.getBookName(),borrower.getName());
        //System.out.println("email2");
        return R.ok();
    }
    @ApiOperation(value = "管理员书评管理")
    @GetMapping("/adminComment")
    public String adminComment(HttpServletRequest request){
        String isLongin = (String) request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminComment";
    }
    @ApiOperation(value = "管理员书评详情")
    @GetMapping("/adminCommentInfo")
    @ResponseBody
    public JsonObject adminCommentInfo(int page, int limit, HttpServletRequest request){
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<Comment> comments = commentService.selectAll(page, limit);
        jsonObject.setData(comments);
        jsonObject.setCount((long)commentService.selectCount());
        return jsonObject;
    }
    @ApiOperation(value = "管理员账号管理")
    @GetMapping("/adminBorrower")
    public String adminBorrower(HttpServletRequest request){
        String isLongin = (String) request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminBorrower";
    }
    @ApiOperation(value = "管理员账号详情")
    @GetMapping("/adminBorrowerInfo")
    @ResponseBody
    public JsonObject adminBorrower(int page, int limit, HttpServletRequest request){
        String name = request.getParameter("name");
        String phoneNum = request.getParameter("phoneNum");
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<Borrower> borrowers = null;
        if(name == null){
            borrowers = borrowerService.selectAll(page,limit);
            jsonObject.setData(borrowers);
            jsonObject.setCount((long)borrowerService.selectCount());
            return jsonObject;
        }
        name = "%" + name + "%";
        phoneNum = "%" + phoneNum + "%";
        borrowers = borrowerService.selectByNameAndPhone(name,phoneNum,page,limit);
        jsonObject.setData(borrowers);
        jsonObject.setCount((long)borrowerService.selectByNameAndPhoneCount(name,phoneNum));
        return jsonObject;
    }
    @ApiOperation(value = "管理员修改读者详情")
    @GetMapping("/adminUpdateBorrower")
    public String adminBorrower(Model model, HttpServletRequest request, int id){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        Borrower borrower = borrowerService.selectById(id);
        //System.out.println(borrower);
        model.addAttribute("borrower", borrower);
        return "admin/adminUpdateBorrower";
    }
    @ApiOperation(value = "管理员修改账号接口")
    @PostMapping("/adminUpdateBorrowerInfo")
    @ResponseBody
    public R adminUpdateBorrowerInfo(HttpServletRequest request,
                                @RequestParam("id") Integer borrowerId,
                                @RequestParam("address") String address,
                                @RequestParam("phone") String phone,
                                     @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Borrower borrower = borrowerService.selectById(borrowerId);
        borrower.setAddress(address);
        borrower.setPhoneNum(phone);
        if(borrowerService.updateBorrowerAddressAndPhone(borrower) == 0){
            BorrowerManagement borrowerManagement = new BorrowerManagement();
            borrowerManagement.setBorrowerId(borrowerId);
            borrowerManagement.setAdminId((int)request.getSession().getAttribute("id"));
            borrowerManagement.setDate(new Date());
            borrowerManagement.setOpType("update");
            borrowerManagementService.insertBorrowerM(borrowerManagement);
            return R.ok();
        }else {
            return R.fail("数据库错误，请稍后再试");
        }
    }
    @ApiOperation(value = "管理员修改读者邮箱")
    @PostMapping("/adminUpdateBorrowerEmail")
    @ResponseBody
    public R adminUpdateBorrowerEmail(HttpServletRequest request,
                                      @RequestParam("id") Integer borrowerId,
                                 @RequestParam("email") String email,
                                      @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Borrower borrower = borrowerService.selectById(borrowerId);
        borrower.setEmail(email);
        if(borrowerService.updateBorrowerEmail(borrower) == 0){
            BorrowerManagement borrowerManagement = new BorrowerManagement();
            borrowerManagement.setBorrowerId(borrowerId);
            borrowerManagement.setAdminId((int)request.getSession().getAttribute("id"));
            borrowerManagement.setDate(new Date());
            borrowerManagement.setOpType("update");
            borrowerManagementService.insertBorrowerM(borrowerManagement);
            return R.ok();
        }else {
            return R.fail("数据库错误，请稍后再试");
        }
    }
    @ApiOperation(value = "管理员修改读者密码")
    @PostMapping("/adminUpdateBorrowerPassword")
    @ResponseBody
    public R adminUpdateBorrowerPassword(HttpServletRequest request,
                                         @RequestParam("id") Integer borrowerId,
                                    @RequestParam("password") String password,
                                         @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Borrower borrower = borrowerService.selectById(borrowerId);
        borrower.setPassword(password);
        if(borrowerService.updateBorrowerPassword(borrower) == 0){
            BorrowerManagement borrowerManagement = new BorrowerManagement();
            borrowerManagement.setBorrowerId(borrowerId);
            borrowerManagement.setAdminId((int)request.getSession().getAttribute("id"));
            borrowerManagement.setDate(new Date());
            borrowerManagement.setOpType("update");
            borrowerManagementService.insertBorrowerM(borrowerManagement);
            return R.ok();
        }else {
            return R.fail("数据库错误，请稍后再试");
        }
    }
    @ApiOperation(value = "管理员删除读者账号")
    @PostMapping("/deleteBorrower")
    @ResponseBody
    public R deleteBorrower(HttpServletRequest request,
                            @RequestParam("id") Integer borrowerId,
                            @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        if(borrowerService.deleteById(borrowerId) == 0){
            BorrowerManagement borrowerManagement = new BorrowerManagement();
            borrowerManagement.setBorrowerId(borrowerId);
            borrowerManagement.setAdminId((int)request.getSession().getAttribute("id"));
            borrowerManagement.setDate(new Date());
            borrowerManagement.setOpType("delete");
            borrowerManagementService.insertBorrowerM(borrowerManagement);
            return R.ok();
        }else {
            return R.fail("数据库错误，请稍后再试");
        }
    }
    @ApiOperation(value = "管理员封禁账号页面")
    @GetMapping("/borrowerBanned")
    public String borrowerBanned(Model model, HttpServletRequest request, int id){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        List<Credit> credits = creditService.selectByBorrowerIdWithoutPage(id);
        model.addAttribute("borrowerId", id);
        model.addAttribute("credits", credits);
        return "admin/borrowerBanned";
    }
    @ApiOperation(value = "管理员解封账号")
    @PostMapping("/relieve")
    @ResponseBody
    public R relieve(HttpServletRequest request,
                     @RequestParam("id") Integer borrowerId,
                     @RequestParam("pwd") String pwd){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        Credit credit = creditService.selectByBorrowerIdWithBreach(borrowerId);
        if(credit == null){
            return R.fail("该账户未被封禁");
        }
        java.sql.Date now = new java.sql.Date(new Date().getTime());
        credit.setBreachEnd(now);
        credit.setIsBreach(false);
        if(creditService.updateCredit(credit) == 0){
            return R.ok();
        }
        return R.fail("请稍后再试");
    }
    @ApiOperation(value = "管理员封禁账号")
    @PostMapping("/ban")
    @ResponseBody
    public R ban(HttpServletRequest request,
                     @RequestParam("id") Integer borrowerId,
                     @RequestParam("pwd") String pwd,
                 @RequestParam("end") String endString) throws ParseException {
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return R.fail("您没有权限");
        }
        if(!confirm(request,pwd)){
            return R.fail("身份验证失败");
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date end = simpleDateFormat.parse(endString);
        Credit credit = creditService.selectByBorrowerIdWithBreach(borrowerId);
        if(credit == null){
            Date start = new Date();
            credit = new Credit();
            credit.setBorrowerId(borrowerId);
            credit.setBorrowerName(borrowerService.selectById(borrowerId).getName());
            credit.setBreachStart(new java.sql.Date(start.getTime()));
            credit.setBreachEnd(new java.sql.Date(end.getTime()));
            credit.setIsBreach(true);
            if(creditService.insertCredit(credit) == 0){
                return R.ok();
            }
        }
        credit.setBreachEnd(new java.sql.Date(end.getTime()));
        if(creditService.updateCredit(credit) == 0){
            return R.ok();
        }
        return R.fail("请稍后再试");
    }
    @ApiOperation(value = "管理员账号操作日志")
    @GetMapping("/adminBorrowerLog")
    public String adminBorrowerLog(HttpServletRequest request){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminBorrowerLog";
    }
    @ApiOperation(value = "管理员账号操作日志详情")
    @GetMapping("/adminBorrowerLogInfo")
    @ResponseBody
    public JsonObject adminBorrowerLogInfo(int page, int limit, HttpServletRequest request){
        String name = request.getParameter("name");
        String phoneNum = request.getParameter("phoneNum");
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<BorrowerManagement>  borrowerManagements = borrowerManagementService.selectAllPage(page,limit);
        jsonObject.setData(borrowerManagements);
        //System.out.println(borrowerManagements);
        jsonObject.setCount((long)borrowerManagementService.selectCount());
        return jsonObject;
    }
    @ApiOperation(value = "管理员书籍操作日志")
    @GetMapping("/adminBookLog")
    public String adminBookLog(HttpServletRequest request){
        String isLongin = (String)request.getSession().getAttribute("isLogin");
        if (isLongin == null || !isLongin.equals("2")) {
            return "notLogin";
        }
        return "admin/adminBookLog";
    }
    @ApiOperation(value = "管理员书籍操作日志详情")
    @GetMapping("/adminBookLogInfo")
    @ResponseBody
    public JsonObject adminBookLogInfo(int page, int limit, HttpServletRequest request){
        String name = request.getParameter("name");
        String phoneNum = request.getParameter("phoneNum");
        JsonObject jsonObject =new JsonObject();
        jsonObject.setCode(0);
        jsonObject.setMsg("ok");
        List<BookManagement>  bookManagements = bookManagementService.selectAllPage(page,limit);
        jsonObject.setData(bookManagements);
        System.out.println(bookManagements);
        jsonObject.setCount((long)bookManagementService.selectCount());
        return jsonObject;
    }
}
